package com.etc.utils;

/**
 * @Author kalista
 * @Description
 * @Date 2020/12/18  9:40
 **/
public class TheadLocalTest {

    static  ThreadLocal<String> threadLocal = new ThreadLocal<>();


    static void print(String str){
        System.out.println(str + ":" +threadLocal.get());
    }



    public static void main(String[] args) {

        Thread thread1 = new Thread(new Runnable() {
            @Override
            public void run() {
                //设置一下当前这个线程值
                threadLocal.set("王聪聪");
                print("我想输出");
                System.out.println(Thread.currentThread().getName());
            }
        });

        Thread thread2 = new Thread(new Runnable() {
            @Override
            public void run() {
                //设置一下当前这个线程值
                threadLocal.set("李连杰");
                print("我想输出");
                System.out.println(Thread.currentThread().getName());
            }
        });



        thread1.start();
        thread2.start();



    }
}
